﻿namespace ufida.u9.ait.openapi
{
	using System;
    using System.Collections;
    using System.Collections.Generic;
	using System.Text;
    using ufida.u9.ait.openapi.utils;
    using UFIDA.U9.ISV.PO;
    using UFIDA.U9.PM.PO;
    using UFSoft.UBF.AopFrame;	
	using UFSoft.UBF.Util.Context;

	/// <summary>
	/// POLineCloseSV partial 
	/// </summary>	
	public partial class POLineCloseSV 
	{	
		internal BaseStrategy Select()
		{
			return new POLineCloseSVImpementStrategy();	
		}		
	}
	
	#region  implement strategy	
	/// <summary>
	/// Impement Implement
	/// 
	/// </summary>	
	internal partial class POLineCloseSVImpementStrategy : BaseStrategy
	{
		public POLineCloseSVImpementStrategy() { }

		public override object Do(object obj)
		{						
			POLineCloseSV bpObj = (POLineCloseSV)obj;

            try
            {
                if (bpObj.Data == null || bpObj.Data.Count == 0)
                    throw new Exception("传入参数为空");

                List<Hashtable> retlist = new List<Hashtable>();
                foreach (POLineCloseAITDTOData linedto in bpObj.Data)
                {
                    String path = $"PurchaseOrder.DocNo='{linedto.DocNo}' and DocLineNo={linedto.DocLineNo}";
                    POLine line = POLine.Finder.Find(path);
                    if (line == null)
                        throw new Exception($"查找不到数据,path:[{path}]");

                    ClosePOLineSRV sv = new ClosePOLineSRV();
                    sv.POLineKeyDTOs = new List<POLineKeyDTO>()
                    {
                        new POLineKeyDTO()
                        {
                            LineKeyDTO=new UFIDA.U9.Base.DTOs.IDCodeNameDTO()
                            {
                                ID=line.ID
                            }
                        }
                    };
                    sv.Do();

                    //处理返回
                    Hashtable ret = new Hashtable();
                    ret.Add("id", line.ID);
                    retlist.Add(ret);
                }

                return ResultUtils.success(bpObj, bpObj.Data, retlist);
            }
            catch (Exception ex)
            {
                return ResultUtils.error(bpObj, bpObj.Data, ex);
            }
        }		
	}

	#endregion
	
	
}